package com.ufo.store.management.utils;

import android.content.res.Resources;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LayoutAnimationController;
import android.view.animation.TranslateAnimation;

public class AnimationUtil {
    public static void setTopToBottomAnimation(ViewGroup group, long dur, float delay) {
        AnimationSet set = new AnimationSet(false);
        Animation animation = new AlphaAnimation(0.4f, 1);   //AlphaAnimation 控制渐变透明的动画效果
        animation.setDuration(dur);     //动画时间毫秒数
        animation.setInterpolator(new DecelerateInterpolator());
        Animation translateAnimation = new TranslateAnimation(0, 0, Utils.dp2px(Resources.getSystem(),-10f), 0);
        translateAnimation.setDuration(dur);//设置动画持续时间为3秒
        translateAnimation.setInterpolator(new DecelerateInterpolator());
        set.addAnimation(animation);    //加入动画集合
        set.addAnimation(translateAnimation);    //加入动画集合
        LayoutAnimationController controller = new LayoutAnimationController(set, delay);
        controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
        group.setLayoutAnimation(controller);   //ViewGroup 设置动画效果
    }

    public static void setBottomToTopAnimation(ViewGroup group, long dur, float delay) {
        AnimationSet set = new AnimationSet(false);
        Animation animation = new AlphaAnimation(0.5f, 1);   //AlphaAnimation 控制渐变透明的动画效果
        animation.setDuration(dur);     //动画时间毫秒数
        animation.setInterpolator(new DecelerateInterpolator());
        Animation translateAnimation = new TranslateAnimation(0, 0, Utils.dp2px(Resources.getSystem(),10f), 0);
        translateAnimation.setDuration(dur);//设置动画持续时间为3秒
        translateAnimation.setInterpolator(new DecelerateInterpolator());
        set.addAnimation(animation);    //加入动画集合
        set.addAnimation(translateAnimation);    //加入动画集合
        LayoutAnimationController controller = new LayoutAnimationController(set, delay);
        controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
        group.setLayoutAnimation(controller);   //ViewGroup 设置动画效果
    }
}
